var context = '/';
/**********判断是否是正整数****************/
function IsInt(s) {
	if (s != null) {
		var r, re;
		re = /\d+/i; //\d表示数字,+表示匹配多个数字
		r = s.match(re);
		return (r == s) ? true : false;
	}
	return false;
}

/******************验证是否为数字 *********************/
function isNumber(oNum) {
	if (!oNum)
		return false;
	var strP = /^\d+(\.\d+)?$/;
	if (!strP.test(oNum))
		return false;
	try {
		if (parseFloat(oNum) != oNum)
			return false;
	} catch (ex) {
		return false;
	}
	return true;
}

String.prototype.trim   =   function() 
{ 
   return   this.replace(/(^\s*)|(\s*$)/g,   ""); 
};

/**检查手机号码是否合法**/
function checkMobilePhone(userId){
	if(userId == ""){
		return false;
	}
	else{
    	if(!IsInt(userId)){
			return false;
		}
    	if(userId.length != 11){
			return false;
    	}
	}
	return true;
}

/** 改变省份 **/
	function changeProvince(){
		var itemValue = $('#provinceInfoSelect').val();
		$.ajax( {
			type : "POST",
			url : context+"painter/painterAction!findCityByProvinceId.do?p_Id="+ itemValue,
			timeout : 6000,
			async : false, //ajax同步
			success : function(data, textStatus) {
				$("#cityInfoSelect").empty();
				$("#cityInfoSelect").append("<option value=''>选择县市</option>");
				var items = eval(data);
				for ( var i = 0; i < items.length; i++) {
					$("#cityInfoSelect").append("<option value='"+items[i].id+"'>" + items[i].name+ "</option>");
				}
			}
		});
	}
	
function changeCity(){
	var itemValue = $('#cityInfoSelect').val();
	var url = context+"front/orderAction!findRegionBycityId.do?c_Id="+ itemValue;
	$.ajax({
		type : "POST",
		url : url,
		timeout : 6000,
		async : false, //ajax同步
		success : function(data, textStatus) {
			$("#regionInfoSelect").empty();
			$("#regionInfoSelect").append("<option value=''>区县</option>");
			var items = eval(data);
			for ( var i = 0; i < items.length; i++) {
				$("#regionInfoSelect").append("<option value='"+items[i].id+"'>" + items[i].name+ "</option>");
			}
		}
	});
}
	
	function checkCity(city_id){
		
		if(city_id == "") return ;
		
		var itemValue = $('#provinceInfoSelect').val();
		$.ajax( {
			type : "POST",
			url : context+"painter/painterAction!findCityByProvinceId.do?p_Id="+ itemValue,
			timeout : 6000,
			async : false, //ajax同步
			success : function(data, textStatus) {
				$("#cityInfoSelect").empty();
				$("#cityInfoSelect").append("<option value=''>选择县市</option>");
				var items = eval(data);
				for ( var i = 0; i < items.length; i++) {
					if(items[i].id == city_id ){
						$("#cityInfoSelect").append("<option value='"+items[i].id+"' selected>" + items[i].name+ "</option>");
					}else{
						$("#cityInfoSelect").append("<option value='"+items[i].id+"'>" + items[i].name+ "</option>");
					}
				}
			}
		});
	}
	
	/************** 检查艺术家是否合法*********************/
	function checkPainter(){
		var flag = false;
		var painter_name = $("#painter_name").val();
		painter_name = encodeURIComponent(painter_name);
		painter_name = encodeURIComponent(painter_name);
		$.ajax({
			type : "POST",
			url : context+"painter/findPainterByName.do?painter_name="+ painter_name,
			timeout : 6000,
			async : false, //ajax同步
			success : function(data, textStatus) {
				if( data >0 ){
					$("#painter").val(data);
					flag = true;
				}else{
					alert("您填写的艺术家不存在，请补充艺术家资料");
					$("#painter_name").focus();
					flag = false;
				}
			}
		});
		return flag ;
	}
	
	/**********************  选择作品形状  **************************************/
	function choosePaintType(sharpId){
		if(sharpId=='1'){  //正方形
			$("#photoTd").css("width","300px");
			$("#photoTd").css("height","300px");
		}
		else if(sharpId=='2'){ //长方形(竖)
			$("#photoTd").css("width","200px");
			$("#photoTd").css("height","300px");
		}
		else if(sharpId=='3'){ //长方形(横)
			$("#photoTd").css("width","300px");
			$("#photoTd").css("height","170px");
		}
		else if(sharpId=='4'){//长卷横披(适合书法作品)
			$("#photoTd").css("width","380px");
			$("#photoTd").css("height","150px");
		}
		else if(sharpId=='5'){//长卷立轴(适合书法作品)
			$("#photoTd").css("width","170px");
			$("#photoTd").css("height","380px");
		}
	}
	
	/**选择已有艺术家**/
	function choosePainter(){
		
		var painterId = $("#painterListSelect").val();
		$("#painter_id").val(painterId);
		
		if(painterId != ""){
			var painter_name = $("select[name='painterListSelect'] option:selected").text(); 
			$("#painter_name").val(painter_name);
		}else{
			$("#painter_name").val("");
		}
	}
	
	function checkChooseSharp(){
		var checkflag = false;
		$($("input[name='painting.sharpInfo.id']:checked")).each(function() {
			checkflag = true;
		});
		return checkflag;
	}
	
function listAvailablePainterList(){
	if($('#painterListSelect') != undefined){
		$.ajax( {
			type : "POST",
			url : context+"/painter/listAvailablePainterList.do",
			timeout : 6000,
			async : false, //ajax同步
			success : function(data, textStatus) {
				$("#painterListSelect").empty();
				$("#painterListSelect").append("<option value=''>选择艺术家</option>");
				var items = eval(data);
				for ( var i = 0; i < items.length; i++) {
					$("#painterListSelect").append("<option value='"+items[i].id+"'>" + items[i].name+ "</option>");
				}
			}
		});
	}
}

function setCookie(key,keyValue,keyExpries,keyDomain,keyPath,secure) {
	var str = key + "=" + escape(keyValue);
	if(keyExpries != null) {
		var exp = new Date();
		exp.setTime(exp.getTime() + keyExpries*1000);

		str = str + "; expires=" + exp.toGMTString();
	}	
	if(keyDomain != null) {
		str = str + "; domain=" + keyDomain;
	}
	if(keyPath != null) {
		str = str + "; path=" + keyPath;
	}
	if(secure == true) {
		str = str + "; true";
	}
	document.cookie = str;
}

function getCookie(key) {
   var search = key + "=";
   if(document.cookie.length > 0) {
      offset = document.cookie.indexOf(search);
      if(offset != -1) {
         offset += search.length;
         end = document.cookie.indexOf(";", offset);
         if(end == -1) end = document.cookie.length;
         return unescape(document.cookie.substring(offset, end));
      }
   }
   return "";
}

function delCookie(key, keyDomain, keyPath) {
	if(key != null) {
		if(getCookie(key) != "") {
			setCookie(key, "", new Date(((new Date()).getTime())).toGMTString(), keyDomain, keyPath);
			return true;
		}
	}
}

function copyToClipboard(txt) {    
    if(window.clipboardData) {    
        window.clipboardData.clearData();    
        window.clipboardData.setData("Text", txt);    
    } else if(navigator.userAgent.indexOf("Opera") != -1) {    
        window.location = txt;    
    } else if (window.netscape) {    
        try {    
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
        } catch (e) {    
            alert("该浏览器不支持,请使用右键菜单复制");    
        }    
    var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
    if (!clip)    
        return;    
    var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
    if (!trans)    
        return;    
    trans.addDataFlavor('text/unicode');    
    var str = new Object();    
    var len = new Object();    
    var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);    
    var copytext = txt;    
    str.data = copytext;    
    trans.setTransferData("text/unicode",str,copytext.length*2);    
    var clipid = Components.interfaces.nsIClipboard;    
    if (!clip)    
        return false;    
    clip.setData(trans,null,clipid.kGlobalClipboard);    
    alert("已成功复制到剪贴板");   
    }    
}

function cleanWhitespace(element) {  
	 //遍历element的子结点  
	 for (var i = 0; i < element.childNodes.length; i++) {  
	  var node = element.childNodes[i];  
	  //判断是否是空白文本结点，如果是，则删除该结点  
	  if (node.nodeType == 3 && !/\S/.test(node.nodeValue))   
	  node.parentNode.removeChild(node);  
	 }  
}

//使表格行上移
function moveUp(){  
	var s = event.srcElement;
	var _tr = s.parentNode.parentNode;
	var index = _tr.rowIndex;
	if (index != 1) {
		var _previousTr = _tr.previousSibling;
		swapNode(_tr, _previousTr);
	} else {
		alert("已经是最上面了");
	}  
}  

//使表格行下移  
function moveDown(){  
	var s = event.srcElement;
	var _tr = s.parentNode.parentNode;
	var intGridviewRowCount = $(".table_tr").length;
	var index = _tr.rowIndex;
	if (index != intGridviewRowCount) {
		var _nextTr = _tr.nextSibling;
		swapNode(_tr, _nextTr);
	} else {
		alert("已经是最下面了");
	}		  
}  

//定义通用的函数交换两个结点的位置  
function swapNode(node1,node2){  
	 //获取父结点  
	 var _parent=node1.parentNode;  
	 //获取两个结点的相对位置  
	 var _t1=node1.nextSibling;  
	 var _t2=node2.nextSibling;  
	 //将node2插入到原来node1的位置  
	 if(_t1)_parent.insertBefore(node2,_t1);  
	 else _parent.appendChild(node2);  
	 //将node1插入到原来node2的位置  
	 if(_t2)_parent.insertBefore(node1,_t2);  
	 else _parent.appendChild(node1);  
}  
function getScrollTop(){
	var scrollPos; 
	if (typeof window.pageYOffset != 'undefined') { 
	   scrollPos = window.pageYOffset; 
	} 
	else if (typeof document.compatMode != 'undefined' && 
	     document.compatMode != 'BackCompat') { 
	   scrollPos = document.documentElement.scrollTop; 
	} 
	else if (typeof document.body != 'undefined') { 
	   scrollPos = document.body.scrollTop; 
	}

	return  scrollPos;
}
function createPopupDiv(divId,width,height,useMask,content){
	
	var divWindow = document.getElementById(divId);
	divWindow.style.display = "block";
	divWindow.style.width = width +"px";
	divWindow.style.height  = height + "px" ;
	var scrollTop = getScrollTop() ;
	divWindow.style.left = (document.body.offsetWidth - width)/2 + document.body.scrollLeft + "px";
	divWindow.style.top  = (window.screen.availHeight - height) / 2 + scrollTop + "px";
	if(useMask) createMask();
	if(content){
		divWindow.innerHTML = content;
	}
}
function closePopupDiv(divId){

	var divWindow = document.getElementById(divId);
	divWindow.style.display = "none";
}
function createMask(){
	var maskDiv = document.createElement("div");
	maskDiv.id= "_link_div_win_mask";
	maskDiv.name= "_link_div_win_mask";
	maskDiv.style.position = "absolute";
	maskDiv.style.backgroundColor = "#000000";
	maskDiv.style.top = "0px";
	maskDiv.style.left = "0px";
	maskDiv.style.width = "100%";
	maskDiv.style.height = "100%";
	maskDiv.style.zIndex = 1000;
	maskDiv.style.opacity = "0.2";
	maskDiv.style.filter = "alpha(opacity=30)";
	var _scrollWidth = document.body.scrollWidth;
	var _scrollHeight = document.body.scrollHeight;
	var _clientWidth = document.body.clientWidth;
	var _clientHeight = document.body.clientHeight;
	maskDiv.style.width = _scrollWidth > _clientWidth ? _scrollWidth : _clientWidth+"px";
	maskDiv.style.height = _scrollHeight > _clientHeight ? _scrollHeight : _clientHeight+"px";
	document.body.appendChild(maskDiv);
	hideSelectBox();
}
function removeMask(){
	showSelectBox();
	document.body.removeChild(document.getElementById('_link_div_win_mask'));	
}
function hideSelectBox(){
	var selectBoxs = document.getElementsByTagName("select");
	for(var i=0;i<selectBoxs.length;i++){
		selectBoxs[i].style.visibility = 'hidden';
	}
}
function showSelectBox(){
	var selectBoxs = document.getElementsByTagName("select");
	for(var i=0;i<selectBoxs.length;i++){
		selectBoxs[i].style.visibility = 'visible';
	}
}

menu1_js= ['m1_002','m1_005','m1_007','m1_008','m1_009','m1_011','m1_012']; 

	function m1(menuId) {
		for ( var i = 0; i < menu1_js.length; i++) {
			var tmpMenu1 = eval("document.getElementById('" + menu1_js[i]
					+ "')");
			var tmpMenu1Div = eval("document.getElementById('div_m1_"
					+ menu1_js[i].substring(3, menu1_js[i].length) + "')");
			if (null != tmpMenu1) {
				if (menuId == menu1_js[i] ) {
					if( null != tmpMenu1Div ){
						tmpMenu1Div.style.display = '';
					}
				} else {
					if( null != tmpMenu1Div ){
						tmpMenu1Div.style.display = 'none';
					}
				}
			}
		}
	}

	function m2(menuId,childMenuId){
		m1(menuId);
		var childMenu1 = eval("document.getElementById('" + childMenuId + "')");
		childMenu1.className = 'menu1_on';
	}
